/*
 * @Date: 2025-02-05 10:35:46
 * @LastEditors: 吴世扬 18368095041@163.com
 * @LastEditTime: 2025-05-28 10:01:09
 * @FilePath: /vue3-admin/src/api/menu.ts
 */

import { request } from '@/utils';
import type { MenuTreeItem, MenuDetial } from '@/typings/api/menu';

export const readMenuTree = () => {
    return request<HttpResult<MenuTreeItem[]>>({
        url: `/admin/api/v1/menu/readTree`,
        method: 'get'
    }).then((res) => {
        return res.data;
    });
};

export const readMenuDetail = (id: number) => {
    return request<HttpResult<MenuDetial>>({
        url: `/admin/api/v1/menu/readDetail/${id}`,
        method: 'get'
    }).then((res) => {
        return res.data;
    });
};

export class MenuParam {
    id?: number;
    type: 1 | 2 = 1;
    name = '';
    path = '';
    parentId?: number;
    icon?: string;
    sortWeight = 1;
}

export const createOrUpdateMenu = (data: MenuParam) => {
    return request<HttpResult>({
        url: '/admin/api/v1/menu/save',
        method: 'post',
        data
    }).then((res) => {
        return res.data;
    });
};

export const deleteMenu = (id: number) => {
    return request<HttpResult>({
        url: `/admin/api/v1/menu/delete/${id}`,
        method: 'post'
    }).then((res) => {
        return res.data;
    });
};
